<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/12/12 0012
 * Time: 10:51
 */

namespace app\admin\controller;
use app\admin\model\Ksb;
use app\admin\model\Bmxx;
use app\admin\model\Kcb;
use app\admin\model\Zp;
use app\admin\model\User;
use think\Controller;
use think\Db;
use app\admin\model\Lyb;
use app\admin\model\Kczs;
class Houtai extends Controller
{
public function index(){
    return $this->fetch();
}
    public function kzt(){
        return $this->fetch();
    }
    public function user(){
    $model=new User();
    $users=$model->getList();
    $this->assign('users',$users);


        return $this->fetch();
    }
    public function zpxx(){
    $model=new Zp();
   $zpxxs= $model->getZpxx();
   $this->assign('zpxxs',$zpxxs);

        return $this->fetch();
    }

    public function zpdel($no){
        $res= db('zp')->where('no',$no)->delete();
        if($res){
            $this->success('删除成功','houtai/zpxx');
        }else{
            $this->error('删除失败');
        }
    }

    public function kcgl(){
    $model=new Kcb();
    $kcbs=$model->getList();
    $this->assign('kcb',$kcbs);
        return $this->fetch();
    }
    public function ksgl(){
        $model=new Ksb();
        $ksbs=$model->getList();
        $this->assign('ksb',$ksbs);

        return $this->fetch();
    }

    public function kcedit($no){
        $model=new Kcb();
        $kcs=$model->getKc($no);

        return $this->fetch('kcedit',['kcb'=>$kcs]);

    }
    public function ksedit($no){
        //获取ks
        $model=new Ksb();
        $ks= $model->getKs($no);

        //获取kc
        $kc_model=new Kcb();
        $kcs= $kc_model->getList();

        return $this->fetch('ksedit',['ksb'=>$ks,'kcb'=>$kcs]);

    }

    public function kcdoedit(){
  $data=  $this->request->param();
  $model=new Kcb();
  $res=$model->isUpdate(true)->save($data);
        if($res){
            $this->success('修改成功','houtai/kcgl');
        }else{
            $this->error('修改失败');
        }
    }
    public function ksdoedit(){
        $data=  $this->request->param();
        $model=new Ksb();
        $res=$model->isUpdate(true)->save($data);
        if($res){
            $this->success('修改成功','houtai/ksgl');
        }else{
            $this->error('修改失败');
        }
    }

    public function kcdel($no){
        $res=db('kcb')->where('no',$no)->delete();
        if($res){
            $this->success('删除成功','houtai/kcgl');
        }else{
            $this->error('删除失败');
        }
    }
    public function ksdel($no){
        $res=db('ksb')->where('no',$no)->delete();
        if($res){
            $this->success('删除成功','houtai/ksgl');
        }else{
            $this->error('删除失败');
        }
    }

    public function kcadd(){
    return $this->fetch();
    }
    public function ksadd(){
        $model=new kcb();
        $kcbs=$model->getList();

        return  $this->fetch('ksadd',['kcb'=>$kcbs]);
    }

    public function kcdoadd(){
   $data=$this->request->param();
   $model=new Kcb();
   $res=$model->save($data);
        if($res){
            $this->success('添加成功','houtai/kcgl');
        }else{
            $this->error('添加失败');
        }
    }

    public function ksdoadd(){
        $data=$this->request->param();
        $model=new Ksb();
        $res=$model->save($data);
        if($res){
            $this->success('添加成功','houtai/ksgl');
        }else{
            $this->error('添加失败');
        }
    }

     public function kccx($name){
    $model=new Kcb();
   $cxs= $model->getcx($name);
   $this->assign('cx',$cxs);
   return $this->fetch();
}

    public function kscx($ksname){
        $model=new Ksb();
        $cxs= $model->getcx($ksname);
        $this->assign('cx',$cxs);
        return $this->fetch();
    }

    public function lyb(){
    $model=new Lyb();
   $lybs= $model->getLyb();
   $this->assign('lybs',$lybs);

        return $this->fetch();
    }
    public function lybdel($no){
        $res= db('lyb')->where('no',$no)->delete();
        if($res){
            $this->success('删除成功','houtai/lyb');
        }else{
            $this->error('删除失败');
        }
    }

    public function qxpz(){
        return $this->fetch();
    }

    public function useredit($no){
    $model=new User();
   $users= $model->getUser($no);
   return $this->fetch('useredit',['user'=>$users]);
    }
  public function userdoedit(){
 $data=$this->request->param();
 $model=new User();
 $res=$model->isUpdate(true)->save($data);
      if($res){
          $this->success('修改成功','houtai/user');
      }else{
          $this->error('修改失败');
      }

  }

    public function useradd(){
        return$this->fetch();
    }
   public function userdoadd(){
    $data=$this->request->param();
    $model=new User();
   $res= $model->save($data);
   if($res){
       $this->success('添加成功','houtai/user');
   }else{
       $this->error('添加失败');
   }
   }

   public function del($no){
       $res= db('user')->where('no',$no)->delete();
       if($res){
           $this->success('删除成功','houtai/user');
       }else{
           $this->error('删除失败');
       }
   }


   public function houtaicx($username){
    $model=new User();
   $users= $model->getCx($username);

       return $this->fetch('houtaicx',['user'=>$users]);
   }

   public function houtaibmxx(){
       $model=new Bmxx();
       $bmxxs= $model->getBmxx();
       $this->assign('bmxxs',$bmxxs);

       return $this->fetch();

   }
   public function bmxxdel($no){
       $res= db('bmxx')->where('no',$no)->delete();
       if($res){
           $this->success('删除成功','houtai/houtaibmxx');
       }else{
           $this->error('删除失败');
       }
   }

}